package com.ktg.mes.qc.service.impl;

import java.util.Arrays;
import java.util.List;
import com.ktg.common.utils.DateUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktg.common.utils.SecurityUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.ktg.mes.qc.mapper.QcReworkRecordMapper;
import com.ktg.mes.qc.domain.QcReworkRecord;
import com.ktg.mes.qc.service.IQcReworkRecordService;



/**
 * 产品检测记录BOMService业务层处理
 *
 * @author byteco
 * @date 2023-02-26
 */
@Service
public class QcReworkRecordServiceImpl extends ServiceImpl<QcReworkRecordMapper, QcReworkRecord> implements IQcReworkRecordService
{




    /**
     * 查询产品检测记录BOM
     *
     * @param entity 产品检测记录BOM
     * @param page 分页对象
     * @return 产品检测记录BOM
     */
    @Override
    public IPage<QcReworkRecord> queryPageList(QcReworkRecord entity, Page<QcReworkRecord> page) {
        QueryWrapper<QcReworkRecord> lqw = new QueryWrapper<QcReworkRecord>(entity);
        lqw.orderByDesc("create_time");
        IPage<QcReworkRecord> pageList = this.page(page, lqw);
        return pageList;
    }

    /**
     * 查询产品检测记录BOM
     *
     * @param entity 产品检测记录BOM
     * @return 产品检测记录BOM
     */
    @Override
    public List<QcReworkRecord> queryList(QcReworkRecord entity) {
        QueryWrapper<QcReworkRecord> lqw = new QueryWrapper<QcReworkRecord>(entity);
        lqw.orderByDesc("create_time");
        return this.list(lqw);
    }

    public QcReworkRecord getInfo(Long id)
    {
        return this.getById(id);
    }


    /**
     * 新增产品检测记录BOM
     *
     * @param entity 产品检测记录BOM
     * @return 结果
     */
    @Override
    public void insert(QcReworkRecord entity)
    {
        entity.setCreateBy(SecurityUtils.getUsername());
        entity.setCreateTime(DateUtils.getNowDate());
        this.save(entity);
    }

    /**
     * 修改产品检测记录BOM
     *
     * @param entity 产品检测记录BOM
     * @return 结果
     */
    @Override
    public boolean update(QcReworkRecord entity)
    {
        entity.setUpdateBy(SecurityUtils.getUsername());
        entity.setUpdateTime(DateUtils.getNowDate());
        return this.updateById(entity);
    }

    /**
     * 批量删除产品检测记录BOM
     *
     * @param reworkRecordIds 需要删除的产品检测记录BOM主键
     * @return 结果
     */
    @Override
    public boolean delete(Long[] reworkRecordIds)
    {

        return this.removeByIds(Arrays.asList(reworkRecordIds));
    }

    /**
     * 删除产品检测记录BOM信息
     *
     * @param reworkRecordId 产品检测记录BOM主键
     * @return 结果
     */
    @Override
    public boolean delete(Long reworkRecordId)
    {
        return this.removeById(reworkRecordId);
    }

    private LambdaQueryWrapper<QcReworkRecord> buildQueryWrapper(QcReworkRecord entity) {
        LambdaQueryWrapper<QcReworkRecord> lqw = Wrappers.lambdaQuery();
                    lqw.eq(StringUtils.isNotBlank(entity.getRecordId()), QcReworkRecord::getRecordId, entity.getRecordId());
                    lqw.eq(entity.getViscosity() != null, QcReworkRecord::getViscosity, entity.getViscosity());
                    lqw.eq(entity.getFineness() != null, QcReworkRecord::getFineness, entity.getFineness());
                    lqw.eq(entity.getPitting() != null, QcReworkRecord::getPitting, entity.getPitting());
                    lqw.eq(entity.getSolventReplenishment() != null, QcReworkRecord::getSolventReplenishment, entity.getSolventReplenishment());
        return lqw;
    }
}
